#ifndef CAMERAWINDOW_H
#define CAMERAWINDOW_H

#include <QMainWindow>
#include <QCamera>
#include <QCameraViewfinder>
#include <QCameraImageCapture>
#include <QLabel>
#include <QPushButton>
#include <QCameraInfo>
#include <QVBoxLayout>
#include <QHBoxLayout>
#include <QDir>
#include <QDateTime>
#include <QDebug>
#include <QTimer>
#include <QTime>
#include <QCoreApplication>
#include <QMessageBox>
#include "tictactoe.h" // 添加 TicTacToe 类头文件
#include "connectAPI.h" // 添加 ContentWidget 头文件
#include "ArmCtrl.h"

class CameraWindow : public QMainWindow
{
    Q_OBJECT

public:
    CameraWindow(QWidget *parent = nullptr);
    ~CameraWindow();
    void stopTimer();
    void startTimer();
    void gameing();
    int FLAG_0_SendImg_OK = 0;
    void resetBoard();
    void ErrorFunc(int errorCode);
    void DoArm(int x,int y);
    void WinHappy(int whoWin);
    QString timeStrText;
    QVector<QVector<int>> previousBoard = {
        {0, 0, 0},
        {0, 0, 0},
        {0, 0, 0}
    };
public slots:
    void captureImage(); // 预留的拍照函数
    void playGame();

private slots:
    void onImageCaptured(int id, const QImage &preview);
    void onImageSaved(int id, const QString &path);
    void updateTimerDisplay(); //用于更新秒表显示

private:
    void setupUI();
    void initCamera();

    QCamera *camera;
    QCameraViewfinder *viewfinder;
    QCameraImageCapture *imageCapture;

    QLabel *capturedImageLabel;
    QPushButton *captureButton;
    QPushButton *playButton;
    QString savePath = QDir::homePath() + "/Pictures/captures/"; // 修改为本机图片路径下的captures目录保存图片

    ContentWidget *contentWidget; // 添加 ContentWidget 类实例

    TicTacToe *ticTacToe; // 添加 TicTacToe 类实例

    Widget *MyArm;


    QTimer *timer;
    QTime *time;
    QLabel *timerLabel; // 新增成员变量用于显示秒表
    qint64 totalMilliseconds;   // 累计总时间（毫秒）
};

#endif // CAMERAWINDOW_H
